﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;

namespace Microsoft.MSE.Catalog.Contracts
{

    [DataContract]
    public class RepositoryChangeSet
    {
        public RepositoryChangeSet()
        {
            this.Items = new List<DBEventContext>();
        }
        public RepositoryChangeSet(bool consolidateChanges)
        {
            this.ConsolidateChanges = consolidateChanges;
            this.Items = new List<DBEventContext>();
        }
        [DataMember]
        public List<DBEventContext> Items { get; set; }
        [DataMember]
        public bool ConsolidateChanges { get; set; }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.MSEEventingNamespaceURI)]
    public class DBEventContext
    {

        private DBEvents eventField;
        private List<DBEventDataItem> dbEventDataItem;
        private DBChangeType changeType;

        public DBEventContext()
        {
            this.EventData = new List<DBEventDataItem>();
        }
        public DBEventContext(DBEvents eventType, DBChangeType changeType)
        {
            this.EventData = new List<DBEventDataItem>();
            this.changeType = changeType;
            this.eventField = eventType;
        }

        [DataMember()]
        public DBEvents Event
        {
            get
            {
                return this.eventField;
            }
            set
            {
                this.eventField = value;
            }
        }
        [DataMember(Name = "EventData", IsRequired = false)]
        public List<DBEventDataItem> EventData
        {
            get
            {
                return this.dbEventDataItem;
            }
            set
            {
                this.dbEventDataItem = value;
            }
        }

        [DataMember(Name="ChangeType")]
        public DBChangeType ChangeType
        {
            get { return this.changeType; }
            set { this.changeType = value; }
        }

    }

    [DataContract(Namespace = SC.MSEEventingNamespaceURI)]
    public enum DBEvents
    {
        [EnumMember]
        EndpointsUpdated,
        [EnumMember]
        EndpointPolicyUpdated,
        [EnumMember]
        ServiceDefinitionUpdated,
        [EnumMember]
        ServicePolicyUpdated,
        [EnumMember]
        OperationsUpdated,
        [EnumMember]
        RuntimeServersUpdated,
        [EnumMember]
        EndpointOpAssociationUpdated,
        [EnumMember]
        EndpointOpPublicationUpdated,
        [EnumMember]
        RuntimeServersBindingUpdated,
        [EnumMember]
        RuntimeServersPolicyUpdated

    }

    [DataContract(Namespace = SC.MSEEventingNamespaceURI)]
    public enum DBChangeType
    {
        [EnumMember]
        Unknown,
        [EnumMember]
        Create,
        [EnumMember]
        Update,
        [EnumMember]
        Delete
    }

    [DataContract(Namespace = SC.MSEEventingNamespaceURI)]
    public class DBEventDataItem
    {
        private Guid runtimeServerId;
        private Guid endpointId;
        private Guid operationId;

        public DBEventDataItem() : this(Guid.Empty) { }
        public DBEventDataItem(Guid runtimeServerId) : this(runtimeServerId, Guid.Empty) { }
        public DBEventDataItem(Guid runtimeServerId, Guid endpointId) : this(runtimeServerId, endpointId, Guid.Empty) { }
        public DBEventDataItem(Guid runtimeServerId, Guid endpointId, Guid operationId)
        {
            this.runtimeServerId = runtimeServerId;
            this.endpointId = endpointId;
            this.operationId = operationId;
        }

        [DataMember]
        public Guid EndpointId
        {
            get { return endpointId; }
            set { endpointId = value; }
        }
        [DataMember]
        public Guid OperationId
        {
            get { return operationId; }
            set { operationId = value; }
        }
        [DataMember]
        public Guid RuntimeServerId
        {
            get { return runtimeServerId; }
            set { runtimeServerId = value; }
        }
        public override int GetHashCode()
        {
            string temp = string.Format("{0}:{1}:{2}", this.RuntimeServerId, this.EndpointId, this.OperationId);
            return temp.GetHashCode();
        }
        public override bool Equals(object obj)
        {
            DBEventDataItem item = obj as DBEventDataItem;
            if (item == null)
                return false;

            if (item.RuntimeServerId == this.RuntimeServerId && item.OperationId == this.OperationId && item.EndpointId == this.EndpointId)
                return true;

            return false;
        }
    }

    [DebuggerStepThrough()]
    [DataContract(Namespace = SC.MSEEventingNamespaceURI)]
    public class Subscribe
    {

        private EndpointReferenceType endToField;

        private DeliveryType deliveryField;

        private string expiresField;

        private FilterType filterField;

        [DataMember]
        public EndpointReferenceType EndTo
        {
            get
            {
                return this.endToField;
            }
            set
            {
                this.endToField = value;
            }
        }

        [DataMember]
        public DeliveryType Delivery
        {
            get
            {
                return this.deliveryField;
            }
            set
            {
                this.deliveryField = value;
            }
        }

        [DataMember]
        public string Expires
        {
            get
            {
                return this.expiresField;
            }
            set
            {
                this.expiresField = value;
            }
        }

        [DataMember]
        public FilterType Filter
        {
            get
            {
                return this.filterField;
            }
            set
            {
                this.filterField = value;
            }
        }
    }

    [DebuggerStepThrough()]
    [DataContract(Namespace = SC.MSEEventingNamespaceURI)]
    public class SubscribeResponse
    {
        private EndpointReferenceType subscriptionManagerField;

        private string expiresField;

        [DataMember]
        public EndpointReferenceType SubscriptionManager
        {
            get
            {
                return this.subscriptionManagerField;
            }
            set
            {
                this.subscriptionManagerField = value;
            }
        }

        [DataMember]
        public string Expires
        {
            get
            {
                return this.expiresField;
            }
            set
            {
                this.expiresField = value;
            }
        }
    }

    [DebuggerStepThrough()]
    [DataContract(Namespace = SC.MSEEventingNamespaceURI)]
    public class FilterType
    {

        private Uri dialectField;
        private string valueField;

        [DataMember]
        public Uri Dialect
        {
            get
            {
                return this.dialectField;
            }
            set
            {
                this.dialectField = value;
            }
        }

        [DataMember]
        public string Value
        {
            get
            {
                return this.valueField;
            }
            set
            {
                this.valueField = value;
            }
        }

    }

    [DebuggerStepThrough()]
    [DataContract(Namespace = SC.MSEEventingNamespaceURI)]
    public class DeliveryType
    {

        private EndpointReferenceType notifyToField;

        private string modeField;

        [DataMember]
        public EndpointReferenceType NotifyTo
        {
            get
            {
                return this.notifyToField;
            }
            set
            {
                this.notifyToField = value;
            }
        }

        [DataMember]
        public string Mode
        {
            get
            {
                return this.modeField;
            }
            set
            {
                this.modeField = value;
            }
        }
    }

    [DebuggerStepThrough()]
    [DataContract(Namespace = SC.MSEEventingNamespaceURI)]
    public partial class EndpointReferenceType
    {

        private Uri addressField;

        private Uri actionField;

        private string referenceParametersField;

        private Guid bindingID;

        [DataMember]
        public Uri Address
        {
            get
            {
                return this.addressField;
            }
            set
            {
                this.addressField = value;
            }
        }

        [DataMember]
        public Uri Action
        {
            get
            {
                return this.actionField;
            }
            set
            {
                this.actionField = value;
            }
        }

        [DataMember]
        public string ReferenceParameters
        {
            get
            {
                return this.referenceParametersField;
            }
            set
            {
                this.referenceParametersField = value;
            }
        }

        [DataMember]
        public Guid BindingID
        {
            get
            {
                return this.bindingID;
            }
            set
            {
                this.bindingID = value;
            }
        }

    }


    [DebuggerStepThrough()]
    [DataContract(Namespace = SC.MSEEventingNamespaceURI)]
    public class Renew
    {

        private string expiresField;

        [DataMember]
        public string Expires
        {
            get
            {
                return this.expiresField;
            }
            set
            {
                this.expiresField = value;
            }
        }
    }

    [DebuggerStepThrough()]
    [DataContract(Namespace = SC.MSEEventingNamespaceURI)]
    public class RenewResponse
    {

        private string expiresField;

        [DataMember]
        public string Expires
        {
            get
            {
                return this.expiresField;
            }
            set
            {
                this.expiresField = value;
            }
        }
    }

    [DebuggerStepThrough()]
    [DataContract(Namespace = SC.MSEEventingNamespaceURI)]
    public class Unsubscribe
    {
    }

    [DebuggerStepThrough()]
    [DataContract(Namespace = SC.MSEEventingNamespaceURI)]
    public class GetStatus
    {
    }

    [DebuggerStepThrough()]
    [DataContract(Namespace = SC.MSEEventingNamespaceURI)]
    public class GetStatusResponse
    {

        private string expiresField;

        [DataMember]
        public string Expires
        {
            get
            {
                return this.expiresField;
            }
            set
            {
                this.expiresField = value;
            }
        }
    }
}
